<%-- 
    Document   : profile
    Created on : Jun 7, 2013, 7:45:56 PM
    Author     : Anna SAELEE
--%>

<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.Connection"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <link type="text/css" rel="stylesheet" href="style.css"/>
        <title>Vos informations</title>
    </head>
    <% Connection conn;
        Statement stmt;
        ResultSet rs;
        try {
            Class.forName("com.mysql.jdbc.Driver");
            conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/dormitorymanagement", "root", "root");
            stmt = conn.createStatement();%>
    <body>
        <div class="wrapper">
            <div class="header"></div>
            <div class="navigator"> <a href="#">MENU</a> > <a href="#">SUBMENU</a> 30*1000 </div>
            <div class="workspace">
                <%@include file="connect.jsp" %>
                <div class="workspace2">
                    <% if (session.getAttribute("username") != null) {
                            String username = (String) session.getAttribute("username");
                            if (username.equals("admin")) {%>
                    Connectez-vous comme le membre de système, s'il vous plaît!
                    <% } else {%>
                    <h3>Information du compte</h3><br/>
                    <% String sql = "SELECT username, password, lastname, firstname, birthday, email, phone_num FROM account WHERE username='" + username + "'";
                        rs = stmt.executeQuery(sql);
                        while (rs.next()) {
                    %>
                    <table width="100%" align="center">
                        <tr>
                            <th>USERNAME</th>
                            <td colspan="2"><%= username%></td>
                        </tr>
                        <tr>
                            <th>PASSWORD</th>
                            <td colspan="2">
                                <form action="updateProfile.jsp" method="post" name="changePwd">
                                    <input type="hidden" name="username" value="<%= username%>"/>
                                    <input type="hidden" name="getChange" value="changePwd"/>
                                    <input type="submit" name="changePwd" value="Change le mot de pass"/>
                                </form>
                            </td>
                        </tr>
                        <tr>
                            <th>NOM</th>
                            <td colspan="2"><%= rs.getString("lastname")%></td>
                        </tr>
                        <tr>
                            <th>PRENOM</th>
                            <td colspan="2"><%= rs.getString("firstname")%></td>
                        </tr>
                        <tr>
                            <th>ANNIVERSAIRE</th>
                            <td colspan="2"><%= rs.getString("birthday")%></td>
                        </tr>
                        <tr>
                            <th>COURRIEL</th>
                            <td><%= rs.getString("email")%></td>
                            <td>
                                <form action="updateProfile.jsp" method="post" name="changeMail">
                                    <input type="hidden" name="username" value="<%= username%>"/>
                                    <input type="hidden" name="getChange" value="changeMail"/>
                                    <input type="submit" name="changeMail" value="Change le courriel"/>
                                </form>
                            </td>
                        </tr>
                        <tr>
                            <th>TELEPHONE</th>
                            <td colspan="2"><%= rs.getString("phone_num")%></td>
                        </tr>
                    </table>
                    <% }

                        }
                    } else {%>
                    Connectez-vous avant, s'il vous plaît!
                    <% }%>
                </div>
                <%@include file="sidespace.jsp" %>
            </div>
            <div class="footer"> FOOTER 80*1000 </div>
        </div>
    </body>
    <% } finally {
            out.close();
        }%>
</html>